package dao;

import entity.Video;
import org.hibernate.Session;
import org.hibernate.query.Query;
import utils.HibernateUtils;

public class VideoDaoImpl implements VideoDao{

    @Override
    public Long TotalVideo() {
        Session session = HibernateUtils.getSession();
        Query query=session.createQuery("select count(*) from entity.Video");
        return (Long) query.uniqueResult();
    }

    @Override
    public Video findOneVideo() {
        Session session = HibernateUtils.getSession();
        Query query=session.createQuery("from entity.Video");
        query.setFirstResult((int) (TotalVideo()-1));
        query.setMaxResults(1);
        return (Video) query.uniqueResult();
    }
}
